//
//  BCHttpBaseRequest.m
//  GSBlockChain
//
//  Created by guoshikeji_a on 2018/11/29.
//  Copyright © 2018 guoshikeji. All rights reserved.
//

#import "BCHttpBaseRequest.h"

#import "NSString+Tool.h"

#import <AFNetworking.h>

#import "NSError+HttpRequest.h"

@implementation BCHttpBaseRequest

- (NSString *)lang {
    return [BCLabguageSettingManager shared].requestLang;
}

- (NSString *)app_id {
    return @"1003";
}

/**
 {
 "Accept-Language" = "en;q=1";
 "User-Agent" = "GSCalendar/1.0 (iPhone; iOS 12.0; Scale/3.00)";
 }
 */
- (NSDictionary *)headerParameter {
//    NSLog(@"%@",self.requestSession.requestSerializer.HTTPRequestHeaders);
    NSMutableDictionary *headers = [NSMutableDictionary dictionaryWithDictionary:self.requestSession.requestSerializer.HTTPRequestHeaders];
    //语言
//    NSString *LocaleIdentifier = @"";
//    NSString *language = @"zh-CN";
//    if ([LocaleIdentifier isEqualToString:@"en"]) {
//        language = @"en";
//    }
//    [headers setObject:language forKey:@"Accept-Language"];
    //jwt
    if ([[BCUserManager sharedUser] isLogin]) {
        NSString *jwt = [BCUserManager sharedUser].userLogin.jwt;
        if (jwt.length) {
            [headers setObject:jwt forKey:@"jwt"];
        }
    }
    return headers;
}






#pragma mark - base层的错误处理
- (void)failure:(NSURLSessionDataTask *)task error:(NSError *)error {
    //主要需要处理http请求状态错误，非服务器定制返回错误
    NSError *parseError = [NSError handleAFErrorWithDataTask:task error:error];
    //
    if (self.requestFailed) {
        self.requestFailed(parseError);
    }
}

@end
